"use strict";

angular.module('app.granaryInfo').controller('InventoryInputCtrl', function($scope,HTTPDataService,Auths){

  if(Auths.getUser())
    {
        var $user = Auths.getUser();
        var  username=  $user.name;
        if($user.rolename == 'admin')
          $scope.showInventory = true;
        else
          $scope.showInventory = false;
       
    } 
   
  
  /* HTTPDataService.getGranaryInventory().then(function(response) {
           $scope.granaryDatas = response;
          
     });*/

     //配置分页基本参数
        $scope.paginationConf = {
            currentPage: 1,
            itemsPerPage: 10,
            pagesLength: 5,
            totalItems:20,
            perPageOptions: [10, 20, 30, 40, 50],
            onChange: function(){
            }
        };

        
     var GetAllEmployee = function () {
 
             HTTPDataService.getGranaryInventoryPagi($scope.paginationConf).then(function (response) {
              
                
                $scope.paginationConf.totalItems = response['sum'];
                $scope.granaryDatas = response['content'];

             });
        }
 
        $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage', GetAllEmployee);

 
   $scope.editGranary = {
                id:'',
                name:username,
                granary_num:'', 
                ending_balance:''
             };
    $scope.showEditGranary = function(item){
         
      $scope.editGranary.id =  item.id; 
      $scope.editGranary.granary_num =  item.granary_num; 
      //$scope.editGranary.ending_balance = item.ending_balance;
     $('#myModalEdit').modal('show') ;
     
   };

     $scope.showEditOutGranary = function(item){
         
      $scope.editGranary.id =  item.id; 
     // $scope.editGranary.ending_balance = item.ending_balance;
     $('#myModalOutEdit').modal('show') ;
     
   };

   $scope.editGranarys = function(){
                                                 
       $('#myModalEdit').modal('hide');
       HTTPDataService.editGranaryInventory($scope.editGranary).then(function(response){
         if(response > 0)
         {
            HTTPDataService.getGranaryInventoryPagi($scope.paginationConf).then(function (response) {
                $scope.paginationConf.totalItems = response['sum'];
                $scope.granaryDatas = response['content'];

             });
  
      $.smallBox({
                    title: "入库成功",
                    content: "<i class='fa fa-clock-o'></i> <i>编辑粮仓成功</i>",
                    color: "#659265",
                    iconSmall: "fa fa-check fa-2x fadeInRight animated",
                    timeout: 4000
                });
         }
         else
         {


         }

       })
       
      
      }

      $scope.editOutGranarys = function(){
                                                 
       $('#myModalOutEdit').modal('hide');
       HTTPDataService.editGranaryOutInventory($scope.editGranary).then(function(response){
         if(response > 0)
         {
            HTTPDataService.getGranaryInventoryPagi($scope.paginationConf).then(function (response) {
               
                $scope.paginationConf.totalItems = response['sum'];
                $scope.granaryDatas = response['content'];

             });
  
      $.smallBox({
                    title: "出库成功",
                    content: "<i class='fa fa-clock-o'></i> <i>编辑粮仓库存成功</i>",
                    color: "#659265",
                    iconSmall: "fa fa-check fa-2x fadeInRight animated",
                    timeout: 4000
                });
         }
         else
         {


         }

       })
       
      
      }  
   

});